/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package thread.demo;

/**
 *
 * @author VANDH
 */
public class JPII {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws InterruptedException {
        //java.lang
        // Integer, Long, Byte -> Wrapper class
        // int, long, byte, short, double float -> primitive data type
        // String, Array, Object, user-defined class -> reference data type (kiểu con trỏ)
//        Integer i = new Integer("123");
//        System.out.println(i);
//
//        int a = i.intValue();
//        Integer.parseInt("123");
//        Integer.valueOf("123");
//        System.out.println(i.compareTo(new Integer(456)));
//
//        // Math
//        double d = Math.random() * 10 + 5;
//
//        // Class class
//        Radio r = new Radio();
//        Class c = r.getClass();
//        System.out.println(c.getName());
//        System.out.println(c.getSuperclass());
//
//        ThreadGroup tg = new ThreadGroup("Money");
//        ThreadGroup tg2 = new ThreadGroup(tg, "MoneyChild");
        stage2();
    }

    private static void stage1() throws InterruptedException {
        // Demo new Thread, new Runnable, sleep, getName, isAlive, join
        Radio radio = new Radio();

        System.out.println("main - Starting radio - " + radio.getName());
        radio.start();
        System.out.println("main - Radio will run in 3s");
        radio.join();
        System.out.println("Radio - isAlive() - " + radio.isAlive());
        Thread airThread = new Thread(new AirConditioner());
        System.out.println("main - Starting radio - " + airThread.getName());
        airThread.start();
        System.out.println("main - AirConditioner run in 3s");
    }

    private static void stage2() throws InterruptedException {
        // Demo new Thread, new Runnable, sleep, getName, isAlive, join
        Radio radio1 = new Radio();
        //Radio radio2 = new Radio();
        Thread a = new Thread(new AirConditioner());
        radio1.setPriority(Thread.MAX_PRIORITY);
        a.setPriority(Thread.MIN_PRIORITY);
        System.out.println("main - Starting radio - " + radio1.getName());
        radio1.start();
        System.out.println("main - Radio will run in 3s");

        a.start();

//        System.out.println("main - Starting radio - " + radio2.getName());
//        radio2.start();
//        System.out.println("main - Radio will run in 3s");
    }
}
